<div id="app">
    <admin-page-header back>
        <bi-button type="primary" @click="$go({action:'itemEdit',gets:{'block':this.$pageData.block_id}})">添加</bi-button>
    </admin-page-header>

    <div class="container">
        <div class="row g-2">
            <div class="col-12">
                <bi-card title="区块内容列表">
                    <bi-table  :data="list" dragsort item-key="blockitem_id" @dragsort="dragsort"  :loading="loading">
                        <bi-table-column label="标题" name="title"></bi-table-column>
                        <bi-table-column label="管理" width="150"  v-slot="{row}">
                            <bi-button type="primary" @click="$go({action:'itemEdit',gets:{'item':row.blockitem_id}})"  >编辑</bi-button>
                            <bi-button type="warning" @click="handleDel(row)" >删除</bi-button>
                        </bi-table-column>
                    </bi-table>
                </bi-card>
            </div>
        </div>
    </div>
</div>


<script>

let app = admin.createApp({
    data(){
        return {
            list:[],
            loading:false,
            page:this.$status.get('page')??1,
            total:0,
            count:0
        }
    },
    methods:{
        refresh(){
            this.loading = true;
            this.$ajax({
                url:this.$url({action:'itemList'}),
                data:{
                    block_id:this.$pageData.block_id,
                    page:this.page
                },
                success:(data)=>{
                    
                    this.list = data.list;
                    this.total = data.total;
                    this.count = data.count;
                    this.loading = false;
                }
            });
        },
        dragsort(value){
           
            this.$loading();

            this.$ajax({
                url:this.$url({action:'itemSort'}),
                data:{
                    block_id:this.$pageData.block_id,
                    ids:value
                },
                success:(res)=>{
                    this.$loading(false)
                    
                }
            })
        },
        handleDel(item){
            this.$confirm('确定删除该项目吗？',()=>{
                this.$loading();
                this.$ajax({
                    url:this.$url({action:'itemDel'}),
                    data:{
                        block_id:this.$pageData.block_id,
                        blockitem_id:item.blockitem_id
                    },
                    success:(res)=>{
                        this.$loading(false)
                        this.refresh();
                    }
                })
            })
        }
    },
    mounted(){
        this.refresh();
    },
}).mount('#app');
</script>